from lib.net.index import http
from utils import common

def get_tts_audio(content):
    """获取文本的tts json"""
    resp = http.POST(
        "http://www.hanxiaoxin.cn:8080/tts",
        {
            "Text": content,
            "Codec": "wav",
            "EmotionCategory": "poetry",
            "VoiceType": 301000,
        },
    )
    audio_base64 = resp["Audio"]
    audio_data = common.decode_base64(audio_base64)
    with open("/audio.wav", "w") as f:
        f.write(audio_data)
    print("save audio wav")
    return audio_base64

def get_tts_audio_raw(content):
    """直接获取文本的tts音频数据"""
    params = {
        "Text": content,
        "Codec": "wav",
        "EmotionCategory": "poetry",
        "VoiceType": 301000,
        "mime": "wav",
    }
    resp = http.POST("http://www.hanxiaoxin.cn:8080/tts", params, "raw")
    return resp